#include <iostream>
#include <vector>

#include "TestCaseGenerator.h"

using namespace std;

void CountingSort(vector<int> &array)
{
	int length = array.size();
	if (length <= 1)
		return;

	int minNum = array[0];
	int maxNum = array[0];

	for (int i = 1; i < length; i++)
	{
		if (array[i] > maxNum)
			maxNum = array[i];
		if (array[i] < minNum)
			minNum = array[i];
	}

	vector<int> arrayFromMinToMax;
	arrayFromMinToMax.resize(maxNum - minNum + 1);
	for each (int var in arrayFromMinToMax)
		var = 0;

	for each (int var in array)
		arrayFromMinToMax[var - minNum] += 1;

	int index = 0;
	for (int i = 0; i < arrayFromMinToMax.size(); i++)
	{
		while (arrayFromMinToMax[i])
		{
			array[index++] = i + minNum;
			arrayFromMinToMax[i] -= 1;
		}
	}
}

int main()
{
	shared_ptr<TestCaseGenerator> tcgPtr;

	vector<int> testCaseArray = tcgPtr->GenerateTestCase(20, 0, 100);
	cout << " Before sort: testCaseArray: " << endl;
	for each (int var in testCaseArray)
		cout << var << " ";
	cout << endl;
	CountingSort(testCaseArray);
	cout << " After sort: testCaseArray: " << endl;
	for each (int var in testCaseArray)
		cout << var << " ";
	cout << endl;

	vector<int> testCaseArray1 = tcgPtr->GenerateTestCase();
	cout << " Before sort: testCaseArray1: " << endl;
	for each (int var in testCaseArray1)
		cout << var << " ";
	cout << endl;
	CountingSort(testCaseArray1);
	cout << " After sort: testCaseArray1: " << endl;
	for each (int var in testCaseArray1)
		cout << var << " ";
	cout << endl;
	

	return 0;
}